library(tidyverse)
library(data.table)
library(tmap)
library(sf)
kenya_5yr_births <- readGoogleSheet("https://docs.google.com/spreadsheets/d/e/2PACX-1vSf-yNXNk68cIOH0Rb6alaDk9SxKEMm3h6kb2p8jxT8oMdfj4OqUDbs2Ln9OOGGCI9V7SNiZJCDWm4H/pubhtml")
kenya_5yr_births <- cleanGoogleTable(kenya_5yr_births , table = 1, skip = 1 ) %>%
setDT()
old_nms_births <- names(kenya_5yr_births)
new_nms_births <- gsub("\\s", "_", old_nms_births) %>%
tolower()
setnames(kenya_5yr_births, old_nms_births, new_nms_births)
numerics_nms <- new_nms_births[new_nms_births != "county"]
kenya_5yr_births[, (numerics_nms) := lapply(.SD, function(x) gsub(",", "", x)), .SDcols = numerics_nms]
kenya_5yr_births[, (numerics_nms) := lapply(.SD, as.numeric), .SDcols = numerics_nms]
kenya_counties <- st_read("County")
## Reading layer `County' from data source `C:\Users\mmburu\Desktop\R\github.io\kenya_population\County' using driver `ESRI Shapefile'
## Simple feature collection with 47 features and 8 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 33.91182 ymin: -4.702271 xmax: 41.90626 ymax: 5.430648
## geographic CRS: WGS 84
ggplot(kenya_counties)+
geom_sf() +
theme_void()

setnames(kenya_counties, "COUNTY", "county")
kenya_5yr_births[, county := tolower(gsub("\\s", "-", county))]
kenya_5yr_births[county == "elgeyo-marakwet", county := "keiyo-marakwet" ]
kenya_5yr_births[county == "nairobi-city" , county := "nairobi"]
kenya_5yr_births[county == "tharaka-nithi" , county := "tharaka" ]
kenya_5yr_births[county == "homabay" , county := "homa-bay" ]
setDT(kenya_counties)
kenya_counties[, county := tolower(gsub("\\s", "-", county))]
kenya_births_counties <- merge(kenya_counties, kenya_5yr_births, by = "county" )
kenya_births_counties <- st_set_geometry(kenya_births_counties, "geometry")
ttm()
tm_shape(kenya_births_counties)+
tm_borders(col = "gold")+
tm_fill(col = "per_cent_in_health_facility")